package cn.tedu._03vehicle.base.exception;

import cn.tedu._03vehicle.base.response.JsonResult;
import cn.tedu._03vehicle.base.response.StatusCode;
import org.springframework.web.bind.MethodArgumentNotValidException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice
public class GlobalExceptionHandler {
    @ExceptionHandler(MethodArgumentNotValidException.class)
    public JsonResult handleIllegalAccessException(MethodArgumentNotValidException e) {
        String date=e.getFieldError().getDefaultMessage();
        return new  JsonResult(StatusCode.MethodArgumentNotValidException,date);
    }
    @ExceptionHandler(Exception.class)
    public JsonResult handleException(Exception e) {
        String  date=e.getMessage();
        return new JsonResult(StatusCode.NOT_LOGIN,date);
    }
}
